<?php

/***************************************************************\
* FILE:		sys/pages/mailtcontents.inc
* SECTION:	pages > sai stuff
* FUNCTION:	manage contents for mails sent to attendees etc
* USES:	
* INCLUDES:		
* PRODUCES:	
* LAUNCHES:	
\***************************************************************/

/**
 * adds extra access checks, dependent on page state
 */
function page_inc_check_access() {
	check_access("ADMIN");
}


/**
 * execute page logic
 */
function page_inc_execute() {
	global $PAGE;
	$CONTENT = array();

	if ($_POST['mail_id'] and !$_POST['submitted']) {
		$sql = db_query_select(array(array("*")), array("MAILCONTENTS"), "mail_id = {$_POST['mail_id']}");
		$mail = db_fetch_array(db_do_query($sql));
		$CONTENT['title'] = $mail['description'];
		$CONTENT['body'] = "<p>Op deze pagina kan u de tekst van een bepaalde mail wijzigen. Daarbij kan u gebruik maken van volgende variabelen, die vervangen zullen worden bij het verzenden van de eigenlijke mail: {$mail['variables']}";
		$inputs = array();
		$inputs[] = form_input_hidden("mail_id", $_POST['mail_id']);
		$inputs[] = form_input_text("Inhoud mail", "mail", db_desqlize($mail['mail']));
		$CONTENT['form'] = form_create("mailform", $inputs);
	} else {
		if ($_POST['submitted'] and $_POST['mail_id'] and $_POST['mail']) {
			$sql = db_query_update(array("mail"), array(db_sqlize($_POST['mail'])), "MAILCONTENTS", "mail_id = {$_POST['mail_id']}");
			db_do_query($sql);
			add_alert("mailing #{$_POST['mail_id']} aangepast");
			add_log("gebruiker #{$_SESSION['user_id']} paste mailing #{$_POST['mail_id']} aan");
		}
		$kv = get_keys_and_values("mail_id", "description", "MAILCONTENTS");
		$CONTENT['title'] = "Pas een mailing aan";
		$CONTENT['form'] = form_create("mailform", array(form_input_select("Kies een mailing", "mail_id", $kv['keys'], $kv['values'], "maak een keuze", "", "document.mailform.submit()", 1, 0, 1)));
	}

	$PAGE['content'] = $CONTENT;
}


/**
 * dress up page content using skin stuff
 */
function page_inc_dress() {
	global $PAGE;
	$CONTENT = $PAGE['content'];
	print_body($CONTENT['body']);
	print_form($CONTENT['form']);
}

?>